/**
 * 包含应用中所有接口请求函数的模块
 * 每个函数的返回值都是Promise
 */
import ajax from './ajax'
const BASE = '/api' // dev环境
// const BASE = '/react_ssm_web' // prod环境

// 登录
export const reqLogin = (loginForm) => ajax(BASE + '/user/login.do', loginForm, 'POST')

/**
 * ********************************** 商品分类 ***********************************************
 */

// 获取商品分类
export const reqParentCateList = (cid) => ajax(BASE + '/category/findAll.do', { cid })

// 添加商品分类
export const reqAddCate = (addCateForm) => ajax(BASE + '/category/add.do', addCateForm, 'POST')

// 更新商品分类
export const reqUpdateCate = (editCateForm) => ajax(BASE + '/category/update.do', editCateForm, 'POST')

// 删除商品分类
export const reqDeleteCate = (id, cid) => ajax(BASE + '/category/delete.do', { id, cid }, 'POST')

// 获取所有权限
export const reqPermission = () => ajax(BASE + '/permission/findAll.do')

// 获取所有角色
export const reqRole = () => ajax(BASE + '/role/findAll.do')

// 获取所有用户
export const reqUser = () => ajax(BASE + '/user/findAll.do')

// 更新用户状态
export const reqUpdateState = (id, state) => ajax(BASE + '/user/changeUserState.do', { id, state }, 'POST')

// 删除用户
export const reqDeleteUser = (id) => ajax(BASE + '/user/deleteUser.do', { id }, 'POST')

// 保存用户
export const reqSaveUser = (addForm) => ajax(BASE + '/user/save.do', addForm, 'POST')

// 删除用户
export const reqUpdateUser = (addForm) => ajax(BASE + '/user/update.do', addForm, 'POST')

// 给角色添加权限
export const reqAddPermission = (commitRole) => ajax(BASE + '/role/addAuthToRole.do', commitRole, 'POST')

/**
 * ********************************* 商品属性 ***********************************************
 */

// 获取商品参数
export const reqCateParams = ( cat_id, attr_sel ) => ajax(BASE + '/goodsParams/findAll.do', { cat_id, attr_sel }, 'POST')

// 新增属性
export const reqAddParams = ( paramsForm ) => ajax(BASE + '/goodsParams/add.do', paramsForm, 'POST')

// 修改属性
export const reqUpdateParams = ( paramsForm ) => ajax(BASE + '/goodsParams/update.do', paramsForm, 'POST')

// 删除属性
export const reqDeleteParams = ( attr_id, attr_sel, cat_id, attr_vals ) => ajax(BASE + '/goodsParams/delete.do', { attr_id, attr_sel, cat_id, attr_vals }, 'POST')

// 添加属性标签
export const reqAddTag = ( attr_id, attr_sel, attr_vals ) => ajax(BASE + '/goodsParams/addTag.do', { attr_id, attr_sel, attr_vals }, 'POST')

// 删除属性标签
export const reqDeleteTag = ( attr_id, attr_sel, attr_vals ) => ajax(BASE + '/goodsParams/deleteTag.do', { attr_id, attr_sel, attr_vals }, 'POST')

/**
 * ********************************** 商品列表 ***********************************************
 */
// 获取商品参数
export const reqGoodsList = ( queryInfo ) => ajax(BASE + '/product/findAll.do', queryInfo)

// 根据id删除指定商品
export const reqDeleteGoods = ( id ) => ajax(BASE + '/product/delete.do', { id }, 'POST')

// 添加商品
export const reqAddGoods = ( goodsForm ) => ajax(BASE + '/product/addProduct.do', goodsForm, 'POST')





